const app = getApp();
const Controller = require('../controllers/controllers.js').controller;
Page({
  data: {
    nick:'',
    sexlist:['男','女'],
    sex:'',
    broth:'',
    relationship:'',
  },
  onLoad: function (options) {
    if(options.parentid){
      app.globalData.parentid=options.parentid
    }
  },
  bindPickerChange: function(e) {
    this.setData({
      index: e.detail.value,
      sex:this.data.sexlist[e.detail.value]
    })
  },
  bindPickerChange2: function(e) {
    this.setData({
      broth: e.detail.value
    })
  },
  changeinput(e){
    var name=e.currentTarget.dataset.name;
    this.setData({
      [name]:e.detail.value
    })
  },
  comfirm(e){
    var data={
      name:this.data.nick,
      relationship:this.data.relationship,
      sex:this.data.sex=='男'?1:2,
      birthday:this.data.broth
    }
    Controller.addFamilyMember(data).then(res=>{
      wx.showToast({
        title: "添加成功",
        icon: 'none',
        duration: 1000
      });
      setTimeout(function(){
        wx.navigateBack({
          delta: 1
        })
      },1000)
    })
    
  },
  onShareAppMessage: function (e) {
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
  onShareTimeline: function(res){
    let title = '';
    let imageUrl = '';
    let path=app.getCurrentPageUrlWithArgs()
    let obj = {
      title,
      imageUrl,
      path,
      success: function (res) {},
      fail(err) {}
    }
    return obj
  },
})